const bodyParser = require('body-parser')
const { list } = require('./src/mock')
module.exports = {
	devServer: {
		before(app) {
			app.use(bodyParser.json())
			
			app.get('/api/home/list', (req, res) => {
				res.send({
					code: 200,
					data: list
				})
			})

			app.post('/api/posts/:id', (req, res) => {
				const id = req.params.id
				const item = list.find(v => v.id === id);

				if(item) {
					res.send({
						code: 200,
						data: item
					})
				} else {
					res.send({
						code: 404,
						data: null,
						mess: '该商品已经下架'
					})
				}
			})
		}
	}
}